global input "Q:\dc1prhcmsas01\PU2\data - sas"
global temp "Q:\dc1prhcmsas01\PU2\temp_stata_wr"
global log "Q:\dc1prhcmsas01\PU2\Log - Stata WR"
global output "Q:\dc1prhcmsas01\PU2\data_stata_wr"
global graphs "Q:\dc1prhcmsas01\PU2\graphs_stata_wr"
global tables "Q:\dc1prhcmsas01\PU2\tables_stata_wr"

cd "Q:\dc1prhcmsas01\PU2\Code - Stata WR"

capture log close
log using "$log/6_fig_diff_distribution_40bin", replace

set scheme plotplain
graph set window fontface "Times New Roman"

*Program for connected plot by base pay
cap program drop plot_connect
program define plot_connect
args var sal sample name legend1 legend2 ylabel ytitle1 ytitle2
	graph twoway (connect `var' bin if salaried==`sal' & `sample'==0 , lc(black) mcolor(black)) ///
		(connect `var' bin if salaried==`sal' & `sample'==1, lc(maroon) mcolor(maroon) msymbol(D)), ///
		xline(455, lcolor(black)) xline(913, lcolor(red)) xtitle("Weekly Base Pay") xlabel(0(500)2500) ///
		l2title(`ytitle1') l1title(`ytitle2') ytitle("") ylabel(`ylabel') legend(order(1 "`legend1'" 2 "`legend2'") ring(0) position(2) col(2) region(lstyle(solid) lcolor(black) lwidth(thin)))
	graph export "$graphs/`name'_40bin.eps", replace
	graph export "$graphs/`name'_40bin.jpg", replace
end 

*Fig 1a:
use "$output\stayers_distribution_treat.dta", clear
keep if yr_month==mdy(04,01,2016) | yr_month==mdy(12,01,2016)
replace bin=floor((bin-913)/40)*40+913
collapse (sum) n, by(yr_month client_id salaried0 bin)

	*Calculate share and collapse by date
	bysort yr_month client_id salaried0: egen emp=sum(n)
	gen share=n/emp
	collapse (mean) share, by(yr_month salaried0 bin)
	drop if bin<=0 | bin>2500
	gen time=yr_month==mdy(12,01,2016)
	
	plot_connect share 1 time fig1a_average_distribution_salaried "April 2016" "December 2016" 0(0.01)0.04 "Share of Salaried Workers"
	plot_connect share 0 time fig1a_average_distribution_hourly "April 2016" "December 2016" 0(0.01)0.08 "Share of Hourly Workers"
	
*Fig 1b:
	*Calculate difference in 2016
	drop yr_month
	reshape wide share, i(salaried bin) j(time)
	gen diff_share=share1-share0
	gen treat=1
	tempfile treat
	save `treat'

	*Calculate difference in 2014
	use "$output\stayers_distribution_control.dta", clear
	keep if yr_month==mdy(04,01,2014) | yr_month==mdy(12,01,2014)
	replace bin=floor((bin-913)/40)*40+913
	collapse (sum) n, by(yr_month client_id salaried0 bin)
	
	bysort yr_month client_id salaried0: egen emp=sum(n)
	gen share=n/emp
	collapse (mean) share, by(yr_month salaried0 bin)
	drop if bin<=0 | bin>2500
	gen time=yr_month==mdy(12,01,2014)
	drop yr_month
	reshape wide share, i(salaried bin) j(time)
	gen diff_share=share1-share0
	gen treat=0 
	append using `treat'
	
	plot_connect diff_share 1 treat fig1b_diff_distribution_salaried "2014" "2016" -0.006(0.002)0.01 "Difference in Share of Salaried Workers" "Between April and December"
	plot_connect diff_share 0 treat fig1b_diff_distribution_hourly "2014" "2016" -0.006(0.002)0.01 "Difference in Share of Hourly Workers" "Between April and December"
	
*Fig 1c:
	*Program for bar plot by base pay
	cap program drop plot_bar
	program define plot_bar
	args var sal ytitle name ylabel

		graph twoway (bar `var' bin if salaried==`sal', barwidth(40)), ///
		xline(455, lcolor(black)) xline(913, lcolor(red)) xline(693 853, lpattern(dot)) ///
		xlabel(0 455 693 853 913 2500, angle(45)) xtitle("Weekly Base Pay") ///
		ytitle(`ytitle') ylabel(`ylabel') legend(off)
		graph export "$graphs/`name'_40bin.eps", replace
		graph export "$graphs/`name'_40bin.jpg", replace

	end
	
	drop share0 share1
	reshape wide diff_share, i(salaried bin) j(treat)
	gen diff_diff=diff_share1-diff_share0
	
	plot_bar diff_diff 1 "Treatment Effect on Share of Salaried Workers" fig1c_diff_diff_distribution_salaried -0.006(0.002)0.01
	plot_bar diff_diff 0 "Treatment Effect on Share of Hourly Workers" fig1c_diff_diff_distribution_hourly -0.006(0.002)0.01
	
log close 